Feeling

Feelings Table

Feelings at time of assessment

Feeling Strongly Disagree Disagree Neutral Agree Strongly Agree
Happy 309 (4%) 693 (9%) 2544 (32%) 3194 (40%) 1325 (16%)
Frustrated 1518 (19%) 3311 (41%) 1692 (21%) 1158 (14%) 386 (5%)
Sad 1637 (20%) 3870 (48%) 1537 (19%) 694 (9%) 327 (4%)
Worried 1476 (18%) 3046 (38%) 1701 (21%) 1404 (17%) 438 (5%)
Restless 1429 (18%) 3093 (38%) 1879 (23%) 1380 (17%) 284 (4%)
Excited 509 (6%) 2070 (26%) 3067 (38%) 1509 (19%) 910 (11%)
Calm 297 (4%) 1031 (13%) 2738 (34%) 2985 (37%) 1014 (13%)
Lonely 1748 (22%) 3278 (41%) 1722 (21%) 748 (9%) 569 (7%)
Bored 1739 (22%) 3430 (43%) 1917 (24%) 757 (9%) 222 (3%)
Sluggish 1415 (18%) 2651 (33%) 1738 (22%) 1567 (19%) 694 (9%)

Feelings Charts

Location

Location Table

Location at time of assessment

Location No Yes
Bus, Train, or Vehicle 7513 (93%) 552 (7%)
Church 7892 (98%) 173 (2%)
Home 2043 (25%) 6022 (75%)
Friend’s or Relative’s House 7601 (94%) 464 (6%)
Store / Mall 7916 (98%) 149 (2%)
Outdoors 7362 (91%) 703 (9%)
Other 7583 (94%) 482 (6%)
Restaurant 8025 (100%) 40 (0%)
School / Library 8065 (100%) 0 (0%)
Work 7933 (98%) 132 (2%)

Location Charts

Activity

Activity Table

Activity at time of assessment

Activity No Yes
Interacting With Someone 5872 (73%) 2193 (27%)
Sitting 4075 (51%) 3990 (49%)
Sleeping 6333 (79%) 1732 (21%)
Standing 6885 (85%) 1180 (15%)
Walking / Excercising 7412 (92%) 653 (8%)
Talking 6454 (80%) 1611 (20%)
Other 6592 (82%) 1473 (18%)

Activity Charts

Physical Activity

Table Row

Physical activity yesterday (Yes / No)

Activity No Yes
Walked or Biked to Get Somewhere 4748 (59%) 3317 (41%)
Engaged in Physical Fitness 6840 (85%) 1225 (15%)
Engaged in Physical Activity at Work or Home 4053 (50%) 4012 (50%)
Did None of These 5948 (74%) 2117 (26%)
Used Pedometer 7749 (96%) 316 (4%)

Physical activity yesterday (Minutes)

Activity 10 Minutes or Less 11-20 Minutes 21-30 Minutes 31-40 Minutes 41-50 Minutes More than 50 Minutes
Walked or Biked to Get Somewhere 283 (9%) 649 (20%) 880 (27%) 638 (19%) 305 (9%) 562 (17%)
Engaged in Physical Fitness 37 (3%) 133 (11%) 252 (21%) 277 (23%) 229 (19%) 297 (24%)
Engaged in Physical Activity at Work or Home 204 (5%) 406 (10%) 852 (21%) 939 (23%) 591 (15%) 1021 (25%)

Sitting time yesterday

Variable 4 or Fewer Hours More than 4 Hours- 6 Hours More than 6 Hours- 8 Hours More than 8 Hours- 10 Hours More than 10 Hours - 12 Hours More than 12 Hours
Sitting Time Yesterday 2220 (28%) 2069 (26%) 1611 (20%) 1278 (16%) 478 (6%) 409 (5%)

Physical Activity Charts

Diet

Table Row

Ate any yesterday (Yes / No)

Food No Yes
Fruit 2729 (34%) 5336 (66%)
Vegetables 1828 (23%) 6237 (77%)
Sugar-Sweetened Beverages 2656 (33%) 5409 (67%)
Deserts and Other Sweets 3580 (44%) 4485 (56%)
Red Meat or Processed Meat 2486 (31%) 5579 (69%)

Servings ate yesterday

Food 0 Servings 1 Serving 2 Servings 3 Servings 4 Servings 5 or More Servings
Fruit 2729 (34%) 2403 (30%) 1745 (22%) 855 (11%) 196 (2%) 137 (2%)
Vegetables 1828 (23%) 2644 (33%) 2283 (28%) 957 (12%) 217 (3%) 136 (2%)
Sugar-Sweetened Beverages 2656 (33%) 1852 (23%) 1400 (17%) 1141 (14%) 381 (5%) 635 (8%)
Deserts and Other Sweets 3580 (44%) 2567 (32%) 1200 (15%) 523 (6%) 145 (2%) 50 (1%)
Red Meat or Processed Meat 2486 (31%) 2479 (31%) 2272 (28%) 701 (9%) 95 (1%) 32 (0%)

Diet Charts

Medication

Medication Table

Did you take all your medication as prescribed yesterday, and if not, which ones didn’t you take?

Medication No Yes
Take Medications 716 (9%) 7347 (91%)
Didn’t Take Depression / Anxiety / Mood Medication 7637 (95%) 428 (5%)
Didn’t Take Psychiatric Medication 7880 (98%) 185 (2%)
Didn’t Take Asthma / COPD Medication 7993 (99%) 72 (1%)
Didn’t Take Blood Pressure Medication 7886 (98%) 179 (2%)
Didn’t Take Diabetes Medication 7935 (98%) 130 (2%)
Didn’t Take Pain Medication 7946 (99%) 119 (1%)
Didn’t Take Cholesterol Medication 7920 (98%) 145 (2%)
Didn’t Take Antibiotic / Antiviral Medication 8037 (100%) 28 (0%)
Didn’t Take Other Medication 7868 (98%) 197 (2%)

Why didn’t you take medications?

Reason Wasn’t a Reason Was a Reason
Ran out 7729 (96%) 336 (4%)
Forgot 7968 (99%) 97 (1%)
Don’t Need It 8053 (100%) 12 (0%)
Side Effects 7957 (99%) 108 (1%)
Got Lost / Stolen 8054 (100%) 11 (0%)
Other 7855 (97%) 210 (3%)

Medication Charts

Freetime

Freetime Table

How much free time did you have yesterday?

Free time 2 or fewer hours More than 2 hours- 4 hours More than 4 hours- 6 hours More than 6 hours- 8 hours More than 8 hours- 10 hours More than 10 hours
Amount 1090 (14%) 1499 (19%) 1773 (22%) 1439 (18%) 1036 (13%) 1226 (15%)

What did you do in your free time yesterday?

Activity Didn’t Do Yesterday Did Yesterday
Watched TV 1264 (16%) 6801 (84%)
Played Computer Games 8065 (100%) 0 (0%)
Went to a Movie 8065 (100%) 0 (0%)
Surfed the Internet 4189 (52%) 3876 (48%)
Read 6028 (75%) 2037 (25%)
Listened to Music or Played Instrument 5764 (71%) 2301 (29%)
Arts and Crafts 6836 (85%) 1229 (15%)
Cleaned 4418 (55%) 3647 (45%)
Took Care of Pets 6548 (81%) 1517 (19%)
Prayed, Meditated, or Went to Religious Service 5511 (68%) 2554 (32%)
Played a Sport 7918 (98%) 147 (2%)
Walk or Jog 6735 (84%) 1330 (16%)
Played Cards, Dice, or Board Games 8065 (100%) 0 (0%)
Went Shopping 6766 (84%) 1299 (16%)
Volunteered 7174 (89%) 891 (11%)
Socialized 5131 (64%) 2934 (36%)
None of These 7848 (97%) 217 (3%)

Freetime Charts

Interaction

Interaction Table

Any meaningful interaction yesterday

Type No Yes
One-On-One Conversations 1556 (19%) 6505 (81%)
Group Interactions 4073 (51%) 3988 (49%)

Amount of meaningful interaction yesterday

Type 15 or Fewer Minutes 16-30 Minutes 31 min- 1 Hour More than 1 Hour- 2 Hours More than 2 Hours- 3 Hours More than 3 Hours- 4 Hours More than 4 Hours
One-On-One Conversations 1556 (19%) 1199 (15%) 1669 (21%) 1595 (20%) 1084 (13%) 387 (5%) 571 (7%)
Group Interactions 4073 (51%) 1010 (13%) 1195 (15%) 1101 (14%) 519 (6%) 48 (1%) 115 (1%)

Interaction Charts

Substances

Substances Tables

Substances used yesterday

Type No Yes
Alcohol 7503 (93%) 562 (7%)
5 or More Alcoholic Drinks 520 (92%) 44 (8%)
Tobacco 4722 (59%) 3343 (41%)
Marijuana 7525 (93%) 540 (7%)
Opiates 7625 (95%) 440 (5%)
Stimulants 8036 (100%) 29 (0%)
Herbal Drugs / Incense 8056 (100%) 9 (0%)
Another drug 8065 (100%) 0 (0%)
None 4184 (52%) 3881 (48%)

Substances Charts

Session Info

R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dataclean_0.1.0     ggplot2_2.1.0       tidyr_0.4.1        
[4] knitr_1.13          dplyr_0.5.0         flexdashboard_0.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.4      magrittr_1.5     munsell_0.4.3    colorspace_1.2-6
 [5] R6_2.1.2         highr_0.5.1      stringr_1.0.0    plyr_1.8.3      
 [9] tools_3.3.1      grid_3.3.1       gtable_0.2.0     DBI_0.4-1       
[13] htmltools_0.3.5  lazyeval_0.2.0   yaml_2.1.13      assertthat_0.1  
[17] digest_0.6.9     tibble_1.1       formatR_1.3      evaluate_0.9    
[21] rmarkdown_0.9.6  labeling_0.3     stringi_1.0-1    scales_0.4.0    
[25] jsonlite_0.9.19 
---
title: "Exploratory Analysis of Daily EMA Data"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    source: embed
---

```{r setup, include=FALSE}
# Setup options
knitr::opts_chunk$set(collapse = TRUE, comment = "")

# CRAN packages
library(flexdashboard)
library(dplyr)
library(knitr)
library(tidyr)
library(ggplot2)

# devtools::install_github("mbcann01/dataclean")
library(dataclean)

# Load ea_kable
source("/Users/bradcannell/Dropbox/Research/mChat/R scripts/ea_kable.R")

# Load data
load("/Users/bradcannell/Dropbox/Research/mChat/data/daily_ema.RData")

# Sort by case number and date
daily <- dplyr::arrange(daily, case_number, date)
```

Overview {.sidebar data-width=300}
===============================================================================

Here we plot the aggregate unconditional distribution of responses for each of the following variables:

1. Feelings at time of assessment

2. Location at time of assessment

3. Activity at time of assessment

4. Physical activity yesterday

5. Diet yesterday

6. Medication use yesterday

7. Freetime activities yesterday

8. Meaningful Interaction yesterday

9. Substance use yesterday

```{r overview}
obs          <- nrow(daily)
vars         <- ncol(daily)
subj         <- length(base::unique(daily$case_number))
n_per_subj   <- count(daily, case_number)
avg_per_subj <- round(mean(n_per_subj$n), 0)
max_n_subj   <- max(n_per_subj$n)
min_n_subj   <- min(n_per_subj$n)
  

cat(paste("The dataset contains: \n", 
  obs, "Observations \n",
  vars, "Variables \n",
  subj, "Unique participants \n",
  "With an average of", avg_per_subj, "\n", "observations each \n",
  "Max =", max_n_subj, "observations \n",
  "Min =", min_n_subj, "observation")
)
```





Feeling
===============================================================================

Feelings Table
-------------------------------------------------------------------------------

### Feelings at time of assessment

```{r feeling_table}
feelings <- select(daily, happy:sluggish)

vars <- tools::toTitleCase(names(feelings))

ea_kable(
  x = feelings, 
  xlab = vars, 
  nrows = 10, 
  ncols = 6, 
  colnames = c("Feeling", "Strongly Disagree", "Disagree", "Neutral", "Agree", 
    "Strongly Agree")
) 
```

Feelings Charts
-------------------------------------------------------------------------------

```{r plot_emotions}
for (var in vars) {
  plot <- ggplot(daily, aes_string(x = tolower(var))) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("I Feel", var, "Right Now")) +
    theme_bw()
  print(plot)
}
```









Location
===============================================================================

Location Table
-------------------------------------------------------------------------------

### Location at time of assessment

```{r location_table}
x <- select(daily, loc_bus:loc_work)

loc <- c("Bus, Train, or Vehicle", "Church", "Home", "Friend's or Relative's House", "Store / Mall", "Outdoors", "Other", "Restaurant", "School / Library", "Work")

ea_kable(
  x = x, 
  xlab = loc, 
  nrows = 10, 
  ncols = 3, 
  colnames = c("Location", "No", "Yes")
)
```

Location Charts
-------------------------------------------------------------------------------

```{r plot_location, fig.width=12}
# Summarize
x <- data.frame(sapply(x, table))

# Tidy data
x <- gather(x)

# Keep even numbered rows
x <- x[c(FALSE, TRUE), ]

# Improve readability
x$key <- loc

# Plot the data
ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Location at Time of Assessment") +
  theme_bw()
```









Activity
===============================================================================

Activity Table
-------------------------------------------------------------------------------

### Activity at time of assessment

```{r activity_table}
x <- select(daily, pre_who, act_sit:act_talk, act_other)

act <- c("Interacting With Someone", "Sitting", "Sleeping", "Standing", "Walking / Excercising", "Talking", "Other")

ea_kable(
  x = x, 
  xlab = act, 
  nrows = 7, 
  ncols = 3, 
  colnames = c("Activity", "No", "Yes")
)
```

Activity Charts
-------------------------------------------------------------------------------

```{r plot_act, fig.width=12}
x <- data.frame(sapply(x, table))
x <- gather(x)
x <- x[c(FALSE, TRUE), ]
x$key <- act

# Plot the data
ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Activity Immediately Prior to Assessment") +
  theme_bw()
```









Physical Activity
===============================================================================

Table Row {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Physical activity yesterday (Yes / No)

```{r physact_table_1}
x <- select(daily, yest_bike, yest_run, yest_cleaning, yest_none, pedometer)

act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Did None of These", "Used Pedometer")

ea_kable(
  x = x, 
  xlab = act, 
  nrows = 5, 
  ncols = 3, 
  colnames = c("Activity", "No", "Yes")
)
```

### Physical activity yesterday (Minutes)

```{r physact_table_2}
x <- select(daily, min_walk, min_run, min_act)

act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home")

ea_kable(
  x = x, 
  xlab = act, 
  nrows = 3, 
  ncols = 7, 
  colnames = c("Activity", "10 Minutes or Less", "11-20 Minutes", "21-30 Minutes", 
    "31-40 Minutes", "41-50 Minutes", "More than 50 Minutes")
)
```

### Sitting time yesterday

```{r sitting_table}
x <- select(daily, min_sit)

ea_kable(
  x = x, 
  xlab = "Sitting Time Yesterday", 
  nrows = 1, 
  ncols = 7, 
  colnames = c("Variable", "4 or Fewer Hours", "More than 4 Hours- 6 Hours", 
    "More than 6 Hours- 8 Hours", "More than 8 Hours- 10 Hours", 
    "More than 10 Hours - 12 Hours", "More than 12 Hours")
)
```

Physical Activity Charts
-------------------------------------------------------------------------------

```{r plot_act_yest}
x <- names(select(daily, yest_bike, yest_run, yest_cleaning, yest_none, pedometer, min_walk, min_run, min_act, min_sit))
act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Did None of These", "Used Pedometer", "Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Sat")
i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste(act[i], "Yesterday")) +
    theme_bw() +
    if (i > 5) {
      theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
    } else {
      theme()
    }
  print(plot)
  i <- i + 1
}

# Plot steps
ggplot(daily, aes(x = steps)) +
  geom_histogram(binwidth = 1000) +
  scale_x_continuous("") +
  ggtitle("Steps Yesterday") +
  theme_bw()
```









Diet
===============================================================================

Table Row {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Ate any yesterday (Yes / No)

```{r diet_table_1}
x <- select(daily, any_fruit, any_veg, any_ssb, any_sweets, any_meat)

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

ea_kable(
  x = x, 
  xlab = food, 
  nrows = 5, 
  ncols = 3, 
  colnames = c("Food", "No", "Yes")
)
```

### Servings ate yesterday

```{r diet_table_2}
x <- select(daily, serv_fruit, serv_veg, serv_ssb, serv_sweets, serv_meat)

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

ea_kable(
  x = x, 
  xlab = food, 
  nrows = 5, 
  ncols = 7, 
  colnames = c("Food", "0 Servings", "1 Serving", "2 Servings", "3 Servings", "4 Servings", 
    "5 or More Servings")
)
```

Diet Charts
-------------------------------------------------------------------------------

```{r diet_yest}
x <- names(select(daily, any_fruit, any_veg, any_ssb, any_sweets, any_meat, serv_fruit, serv_veg, serv_ssb, serv_sweets, serv_meat))

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat", "Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Ate", food[i], "Yesterday")) +
    theme_bw()
  print(plot)
  i <- i + 1
}
```









Medication
===============================================================================

Medication Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Did you take all your medication as prescribed yesterday, and if not, which ones didn't you take?

```{r med_table_1}
x <- select(daily, take_meds, medtype_dep, medtype_psy, medtype_ast, medtype_bp, medtype_diab, medtype_pain, medtype_chol, medtype_anti, medtype_other)

xlab <- c("Take Medications", "Didn't Take Depression / Anxiety / Mood Medication", "Didn't Take Psychiatric Medication", "Didn't Take Asthma / COPD Medication", "Didn't Take Blood Pressure Medication", "Didn't Take Diabetes Medication", "Didn't Take Pain Medication", "Didn't Take Cholesterol Medication", "Didn't Take Antibiotic / Antiviral Medication", "Didn't Take Other Medication")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 10, 
  ncols = 3, 
  colnames = c("Medication", "No", "Yes")
)
```

### Why didn't you take medications?

```{r med_table_2}
x <- select(daily, meds_ran_out, meds_forgot, meds_no_need, meds_side, meds_lost, meds_other)

xlab <- c("Ran out", "Forgot", "Don't Need It", "Side Effects", "Got Lost / Stolen", "Other")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 6, 
  ncols = 3, 
  colnames = c("Reason", "Wasn't a Reason", "Was a Reason")
)
```

Medication Charts
-------------------------------------------------------------------------------
```{r med_chart, fig.width=12}
# Take Meds (Yes / No)
x <- select(daily, take_meds)
ggplot(x, aes(x = take_meds)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle("Take All Medications as Prescribed Yesterday") +
    theme_bw()

# Which medications not taken
x <- select(daily, medtype_dep, medtype_psy, medtype_ast, medtype_bp, medtype_diab, medtype_pain, medtype_chol, medtype_anti, medtype_other)

xlab <- c("Depression / Anxiety / Mood", "Psychiatric", "Asthma / COPD", "Blood Pressure", "Diabetes", "Pain", "Cholesterol", "Antibiotic / Antiviral", "Other")

x <- data.frame(sapply(x, table))
x <- gather(x)
x <- x[c(FALSE, TRUE), ]
x$key <- xlab

ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Medication Not Taken Yesterday") +
  theme_bw()

# Why medication not taken
x <- select(daily, meds_ran_out, meds_forgot, meds_no_need, meds_side, meds_lost, meds_other)

xlab <- c("Ran out", "Forgot", "Don't Need It", "Side Effects", "Got Lost / Stolen", "Other")

x <- data.frame(sapply(x, table))
x <- gather(x)
x <- x[c(FALSE, TRUE), ]
x$key <- xlab

ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Reason Medication Not Taken Yesterday") +
  theme_bw()
```









Freetime
===============================================================================

Freetime Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### How much free time did you have yesterday?

```{r freetime_table_1}
x <- select(daily, free_time)

xlab <- c("Amount")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 1, 
  ncols = 7, 
  colnames = c("Free time", "2 or fewer hours", "More than 2 hours- 4 hours", 
    "More than 4 hours- 6 hours", "More than 6 hours- 8 hours", "More than 8 hours- 10 hours", 
    "More than 10 hours")
)
```

### What did you do in your free time yesterday?

```{r freetime_table_2}
x <- select(daily, free_tv:free_social, free_none)

xlab <- c("Watched TV", "Played Computer Games", "Went to a Movie", "Surfed the Internet", "Read", "Listened to Music or Played Instrument", "Arts and Crafts", "Cleaned", "Took Care of Pets", "Prayed, Meditated, or Went to Religious Service", "Played a Sport", "Walk or Jog", "Played Cards, Dice, or Board Games", "Went Shopping", "Volunteered", "Socialized", "None of These")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 17, 
  ncols = 3, 
  colnames = c("Activity", "Didn't Do Yesterday", "Did Yesterday")
)
```

Freetime Charts
-------------------------------------------------------------------------------
```{r freetime_chart, fig.width=12, fig.height=8}
# How much
x <- select(daily, free_time)

xlab <- c("Amount")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle("Amount of Free Time Yesterday") +
    theme_bw() +
    theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
  print(plot)
  i <- i + 1
}

# What they did during free time
x <- select(daily, free_tv:free_social, free_none)

xlab <- c("Watched TV", "Played Computer Games", "Went to a Movie", "Surfed the Internet", "Read", "Listened to Music or Played Instrument", "Arts and Crafts", "Cleaned", "Took Care of Pets", "Prayed, Meditated, or Went to Religious Service", "Played a Sport", "Walk or Jog", "Played Cards, Dice, or Board Games", "Went Shopping", "Volunteered", "Socialized", "None of These")

x <- data.frame(sapply(x, table))
x <- gather(x)
x <- x[c(FALSE, TRUE), ]
x$key <- xlab

ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Free Time Activity Yesterday") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
```









Interaction
===============================================================================

Interaction Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Any meaningful interaction yesterday

```{r interaction_table_1}
x <- select(daily, any_talk, any_group)

xlab <- c("One-On-One Conversations", "Group Interactions")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 2, 
  ncols = 3, 
  colnames = c("Type", "No", "Yes")
)
```

### Amount of meaningful interaction yesterday

```{r interaction_table_2}
x <- select(daily, min_talk, min_group)

xlab <- c("One-On-One Conversations", "Group Interactions")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 2, 
  ncols = 8, 
  colnames = c("Type", "15 or Fewer Minutes", "16-30 Minutes", "31 min- 1 Hour", 
    "More than 1 Hour- 2 Hours", "More than 2 Hours- 3 Hours", "More than 3 Hours- 4 Hours", 
    "More than 4 Hours")
)
```

Interaction Charts
-------------------------------------------------------------------------------
```{r interaction_chart}
# Any interaction
x <- select(daily, any_talk, any_group)

xlab <- c("One-On-One Conversations", "Group Interactions")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste(xlab[i], "Yesterday")) +
    theme_bw()
  print(plot)
  i <- i + 1
}
  
# Amount of interaction
x <- select(daily, min_talk, min_group)

xlab <- c("One-On-One Conversations", "Group Interactions")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Amount of", xlab[i], "Yesterday")) +
    theme_bw() +
    theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
  print(plot)
  i <- i + 1
}
```









Substances
===============================================================================

Substances Tables
-------------------------------------------------------------------------------

### Substances used yesterday

```{r substance_table}
x <- select(daily, sub_alc, heavy_drink, sub_cig, sub_mar, sub_opi, sub_stim, sub_herb, sub_other, sub_none)

xlab <- c("Alcohol", "5 or More Alcoholic Drinks", "Tobacco", "Marijuana", "Opiates", "Stimulants", "Herbal Drugs / Incense", "Another drug", "None")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 9, 
  ncols = 3, 
  colnames = c("Type", "No", "Yes")
)
```

Substances Charts
-------------------------------------------------------------------------------

```{r substance_chart}
x <- names(select(daily, sub_alc, heavy_drink, sub_cig, sub_mar, sub_opi, sub_stim, sub_herb, sub_other, sub_none))
sub <- c("Alcohol", "Tobacco", "Marijuana", "Opiates", "Stimulants", "Herbal Drugs", "Another drug", "No Substances")
i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Participant used", sub[i], "Yesterday")) +
    theme_bw()
  print(plot)
  i <- i + 1
}
```




Session Info
===============================================================================
```{r session_info, echo=FALSE}
sessionInfo()
```